<template>
  <div>
    <BreadCrumb></BreadCrumb>
    <div class="header">
        <div class="form">
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="用户名">
              <el-input v-model="formInline.username" size="small" placeholder="用户名"></el-input>
            </el-form-item>
            <el-form-item label="姓名">
              <el-input v-model="formInline.name" size="small" placeholder="姓名"></el-input>
            </el-form-item>
            <el-form-item label="注册时间">
              <el-date-picker v-model="formInline.date" size="small" type="date" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit" size="small">查询</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="group">
          <!-- <el-button size="small" type="warning" icon="el-icon-plus" @click="toProductPage">添加</el-button> -->
          <el-button size="small" type="danger" icon="el-icon-delete">批量冻结</el-button>
        </div>
    </div>
    <div class="content">
      <el-table
      :data="tableData"
      @select="selectHandle"
      @select-all="selectHandle"
      style="width: 100%" stripe border :default-sort = "{prop: 'date', order: 'descending'}">
      <el-table-column
      align="center"
      type="selection"
      width="55">
        </el-table-column>
          <el-table-column
          sortable
          align="center"
            prop="createTime"
            label="注册时间"
            width="180">
          </el-table-column>
          <el-table-column
          sortable
          align="center"
            prop="username"
            label="用户名"
            width="180">
            <template slot-scope="scope">
              <span style="color: blue;cursor: pointer;" @click="handleLook(scope.$index,scope.row)">
                {{ scope.row.username }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
          sortable
          align="center"
            prop="name"
            label="姓名"
            width="180">
          </el-table-column>
          <el-table-column
          align="center"
            prop="phone"
            label="联系电话">
          </el-table-column>
          <el-table-column
          align="center"
            prop="symptoms"
            label="症状">
          </el-table-column>
          <el-table-column label="操作"  align="center">
          <template slot-scope="scope">
            <el-button
            v-if="scope.row.status==0"
            icon="el-icon-delete"
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">冻结</el-button>
              <el-button
            v-if="scope.row.status==1"
            icon="el-icon-setting"
              size="mini"
              type="success"
              @click="handleDelete(scope.$index, scope.row)">解冻</el-button>
          </template>
        </el-table-column>
      </el-table>
        <div class="pagination">
          <Pagination :total="total" :pageSize="pageSize" @CurrentChange="getRecords" :page="page" obj="user"></Pagination>
        </div>
    </div>
  </div>
</template>

<script>
import Pagination  from '@/components/pagination/myPagination.vue';
import axios from 'axios';
import dayjs from 'dayjs';
export default {
  components:{Pagination},
  data(){
    return{
      total:60,
      pageSize:6,
      page:1,
      formInline: {
        username:'',
        name: '',
        date: ''
      },
      tableData:[]
    }
  },
  mounted(){
    axios({
      url:'http://localhost:8080/polycystic/user/page',
      method:'post',
      headers:{
        token:localStorage.getItem('jwt')
      },
      data:{
        page:this.page,
        pageSize:this.pageSize
      }
    }).then(res=>{
      console.log(res.data.data);
      this.tableData=res.data.data.records
      for(let i=0;i<this.tableData.length;i++){
        this.tableData[i].status=0
      }
    })
  },
  methods:{
    getRecords(val){
      this.tableData=val
    },
    onSubmit() {
      let createTime=''
      if(this.formInline.date){
        createTime=dayjs(this.formInline.date).format('YYYY-MM-DD')
      }
      axios({
      url:'http://localhost:8080/polycystic/user/page',
      method:'post',
      headers:{
        token:localStorage.getItem('jwt')
      },
      data:{
        page:this.page,
        pageSize:this.pageSize,
        name:this.formInline.name,
        username:this.formInline.username,
        createTime:createTime
      }
    }).then(res=>{
      this.tableData=res.data.data.records
    })
      console.log('submit!', this.formInline.name);
    },
    selectHandle(selection){
      console.log(selection);
    },
    handleEdit(index, row) {
        console.log(index, row);
        // 跳转编辑页面
        this.$router.push('/user/userPage')
      },
    handleDelete(index, row) {
      console.log(index, row);
    },
    toProductPage(){
      this.$router.push('/user/userPage')
    },
    // 查看商品详情
    handleLook(index,row){
      console.log(index, row);
      this.$router.push({
        name:'userPage',
        params:{
          userInfo:row
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .header{
    background: #FFF;
    margin-bottom: 20px;
    padding: 10px;
    .el-form-item{
      margin-bottom: 16px;
    }
    .group{
      border: 1px solid #eee;
      padding: 8px;
    }
  }
  .content{
    background: #FFF;
    .pagination{
      padding: 10px;
    }
  }
</style>